using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VLSTAX
    {
        public DataRow Convert2LSTAX(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryLSTAX(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["LSXMANDANT"] = " ".PadRight(2 ); 
         dwReturn["LSXLIEFNR"] = " ".PadRight(8 ); 
         dwReturn["LSXADRSL"] = " ".PadRight(8 ); 
         dwReturn["LSXTAXNR1"] = " ".PadRight(20 ); 
         dwReturn["LSXTAXDAT1"] = " ".PadRight(0 ); 
         dwReturn["LSXTAXCL1"] = " ".PadRight(2 ); 
         dwReturn["LSXTAXNR2"] = " ".PadRight(20 ); 
         dwReturn["LSXTAXDAT2"] = " ".PadRight(0 ); 
         dwReturn["LSXTAXCL2"] = " ".PadRight(2 ); 
         dwReturn["LSXTAXNR3"] = " ".PadRight(20 ); 
         dwReturn["LSXTAXDAT3"] = " ".PadRight(0 ); 
         dwReturn["LSXTAXCL3"] = " ".PadRight(2 ); 
         dwReturn["LSXTAXNR4"] = " ".PadRight(20 ); 
         dwReturn["LSXTAXDAT4"] = " ".PadRight(0 ); 
         dwReturn["LSXTAXCL4"] = " ".PadRight(2 ); 
         dwReturn["LSXTAXNR5"] = " ".PadRight(20 ); 
         dwReturn["LSXTAXDAT5"] = " ".PadRight(0 ); 
         dwReturn["LSXTAXCL5"] = " ".PadRight(2 ); 
         dwReturn["LSXTAXNR6"] = " ".PadRight(20 ); 
         dwReturn["LSXTAXDAT6"] = " ".PadRight(0 ); 
         dwReturn["LSXTAXCL6"] = " ".PadRight(2 ); 
         dwReturn["LSXFILLER"] = " ".PadRight(50 ); 
         dwReturn["LSXAENZL"] = " ".PadRight(0 ); 
         dwReturn["LSXAENB"] = " ".PadRight(8 ); 
         dwReturn["LSXAEND"] = " ".PadRight(0 ); 
         dwReturn["LSXNEUB"] = " ".PadRight(8 ); 
         dwReturn["LSXNEUD"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapLSTAX(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveLSTAX(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryLSTAX(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapLSTAX(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertLSTAX(dwLocal, ITXDBVERSION);
            }
            UpdateLSTAX(dwLocal);
        }
        public void InsertLSTAX(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO LSTAX(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryLSTAX(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM LSTAX WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM LSTAX  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "LSTAX";
            Return = Result;
            return Return;
        }
        public void DeleteLSTAX(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM LSTAX   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateLSTAX(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE LSTAX SET "
                    +"LSXMANDANT= :LSXMANDANT,"
                    +"LSXLIEFNR= :LSXLIEFNR,"
                    +"LSXADRSL= :LSXADRSL,"
                    +"LSXTAXNR1= :LSXTAXNR1,"
                    +"LSXTAXDAT1= :LSXTAXDAT1,"
                    +"LSXTAXCL1= :LSXTAXCL1,"
                    +"LSXTAXNR2= :LSXTAXNR2,"
                    +"LSXTAXDAT2= :LSXTAXDAT2,"
                    +"LSXTAXCL2= :LSXTAXCL2,"
                    +"LSXTAXNR3= :LSXTAXNR3,"
                    +"LSXTAXDAT3= :LSXTAXDAT3,"
                    +"LSXTAXCL3= :LSXTAXCL3,"
                    +"LSXTAXNR4= :LSXTAXNR4,"
                    +"LSXTAXDAT4= :LSXTAXDAT4,"
                    +"LSXTAXCL4= :LSXTAXCL4,"
                    +"LSXTAXNR5= :LSXTAXNR5,"
                    +"LSXTAXDAT5= :LSXTAXDAT5,"
                    +"LSXTAXCL5= :LSXTAXCL5,"
                    +"LSXTAXNR6= :LSXTAXNR6,"
                    +"LSXTAXDAT6= :LSXTAXDAT6,"
                    +"LSXTAXCL6= :LSXTAXCL6,"
                    +"LSXFILLER= :LSXFILLER,"
                    +"LSXAENZL= :LSXAENZL,"
                    +"LSXAENB= :LSXAENB,"
                    +"LSXAEND= :LSXAEND,"
                    +"LSXNEUB= :LSXNEUB,"
                    +"LSXNEUD= :LSXNEUD,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("LSXMANDANT", OracleType.NVarChar).Value = dwData["LSXMANDANT"].ToString(); 
          or1.Parameters.Add("LSXLIEFNR", OracleType.NVarChar).Value = dwData["LSXLIEFNR"].ToString(); 
          or1.Parameters.Add("LSXADRSL", OracleType.NVarChar).Value = dwData["LSXADRSL"].ToString(); 
          or1.Parameters.Add("LSXTAXNR1", OracleType.NVarChar).Value = dwData["LSXTAXNR1"].ToString(); 
          or1.Parameters.Add("LSXTAXDAT1", OracleType.NVarChar).Value = dwData["LSXTAXDAT1"].ToString(); 
          or1.Parameters.Add("LSXTAXCL1", OracleType.NVarChar).Value = dwData["LSXTAXCL1"].ToString(); 
          or1.Parameters.Add("LSXTAXNR2", OracleType.NVarChar).Value = dwData["LSXTAXNR2"].ToString(); 
          or1.Parameters.Add("LSXTAXDAT2", OracleType.NVarChar).Value = dwData["LSXTAXDAT2"].ToString(); 
          or1.Parameters.Add("LSXTAXCL2", OracleType.NVarChar).Value = dwData["LSXTAXCL2"].ToString(); 
          or1.Parameters.Add("LSXTAXNR3", OracleType.NVarChar).Value = dwData["LSXTAXNR3"].ToString(); 
          or1.Parameters.Add("LSXTAXDAT3", OracleType.NVarChar).Value = dwData["LSXTAXDAT3"].ToString(); 
          or1.Parameters.Add("LSXTAXCL3", OracleType.NVarChar).Value = dwData["LSXTAXCL3"].ToString(); 
          or1.Parameters.Add("LSXTAXNR4", OracleType.NVarChar).Value = dwData["LSXTAXNR4"].ToString(); 
          or1.Parameters.Add("LSXTAXDAT4", OracleType.NVarChar).Value = dwData["LSXTAXDAT4"].ToString(); 
          or1.Parameters.Add("LSXTAXCL4", OracleType.NVarChar).Value = dwData["LSXTAXCL4"].ToString(); 
          or1.Parameters.Add("LSXTAXNR5", OracleType.NVarChar).Value = dwData["LSXTAXNR5"].ToString(); 
          or1.Parameters.Add("LSXTAXDAT5", OracleType.NVarChar).Value = dwData["LSXTAXDAT5"].ToString(); 
          or1.Parameters.Add("LSXTAXCL5", OracleType.NVarChar).Value = dwData["LSXTAXCL5"].ToString(); 
          or1.Parameters.Add("LSXTAXNR6", OracleType.NVarChar).Value = dwData["LSXTAXNR6"].ToString(); 
          or1.Parameters.Add("LSXTAXDAT6", OracleType.NVarChar).Value = dwData["LSXTAXDAT6"].ToString(); 
          or1.Parameters.Add("LSXTAXCL6", OracleType.NVarChar).Value = dwData["LSXTAXCL6"].ToString(); 
          or1.Parameters.Add("LSXFILLER", OracleType.NVarChar).Value = dwData["LSXFILLER"].ToString(); 
          or1.Parameters.Add("LSXAENZL", OracleType.NVarChar).Value = dwData["LSXAENZL"].ToString(); 
          or1.Parameters.Add("LSXAENB", OracleType.NVarChar).Value = dwData["LSXAENB"].ToString(); 
          or1.Parameters.Add("LSXAEND", OracleType.NVarChar).Value = dwData["LSXAEND"].ToString(); 
          or1.Parameters.Add("LSXNEUB", OracleType.NVarChar).Value = dwData["LSXNEUB"].ToString(); 
          or1.Parameters.Add("LSXNEUD", OracleType.NVarChar).Value = dwData["LSXNEUD"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
